//
//  EPMMainTabBarController.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/4/26.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMMainTabBarController.h"
#import "EPMNavigationController.h"
#import "HMAlphaAnimator.h"
#import "EPMMainTabBar.h"

@interface EPMMainTabBarController ()
@property (strong,nonatomic) HMAlphaAnimator* animator;
@end

@implementation EPMMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupTabBars];
    [self setupModalPresentation];
    //自定义tabbar
    EPMMainTabBar* epmTabBar = [[EPMMainTabBar alloc]init];
    
    [self setValue:epmTabBar forKey:@"tabBar"];
    //设置字体渲染颜色
    self.tabBar.tintColor =  appColor;
    
    
    
    
    
}

- (void)setupTabBars{
    
    
    [self addNavControllerWithViewController:@"EPMHomeViewController" title:@"首页" imgName:@"v2_home"];
    [self addNavControllerWithViewController:@"EPMSuperMarketViewController" title:@"闪电超市" imgName:@"v2_order"];
    [self addNavControllerWithViewController:@"EPMShoppingCarViewController" title:@"购物车" imgName:@"shopCart"];
    [self addNavControllerWithViewController:@"EPMMineViewController" title:@"我的" imgName:@"v2_my"];
    
    
}


- (void)addNavControllerWithViewController:(NSString*)clsName title:(NSString*)title imgName:(NSString*)imgName{
    
    Class cls = NSClassFromString(clsName);
    UIViewController* controller = [cls new];
    EPMNavigationController* navController = [[EPMNavigationController alloc]initWithRootViewController:controller];
    //设置字体渲染颜色
    self.tabBar.tintColor = [UIColor colorWithRed:254/255.0 green:213/255.0 blue:48/255.0 alpha:1.0];
    
    navController.tabBarItem.title = title;
    [navController.tabBarItem setImage:[UIImage imageNamed:imgName]];
    [navController.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_r",imgName]]];
    
   
    
    [self addChildViewController:navController];
}

#pragma mark - 设置动画效果 -
- (void)setupModalPresentation{
    // 1. 设置modal展示样式
    self.modalPresentationStyle = UIModalPresentationCustom;
    
    
    self.animator = [HMAlphaAnimator new];
    
    
    // 2. 设置转场代理 -> 自定义转场动画
    self.transitioningDelegate = self.animator;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
